package cate.game.play.buff.h;

import cate.common.util.XT;
import cate.game.attr.FightAttr;
import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.effect.SkillEffect;

import java.util.List;

/**
 * 效果：叠加三层后清除，损失基于施法者攻击力180%的生命值，持续到战斗结束
 * 强化效果：目标每携带1层【酗酒】，对其造成的伤害就提高5%
 */
public class 酗酒BH extends BuffHandler {

	private int 层数;

	private List<Integer> 附加buff;

	private FightAttr 临时属性;

	//层数=3&附加buff=??#??&临时属性=23:500
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		层数 = args.getInt("层数", 0);
		附加buff = args.getIntList("附加buff");
		临时属性 = new FightAttr(args.get("临时属性"));
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		附加buff = XT.merge(附加buff, args.getIntList("附加buff"));
		临时属性.add(new FightAttr(args.get("临时属性")));
	}


	@Override
	public void onAdd(ActionCtx action) {
		if (buff.owner.buff.countBuffByTid(buff.tid) >= 层数) {
			if (XT.isNotBlank(附加buff)) {
				for (Integer tid : 附加buff) {
					buff.owner.buff.tryAddByTid(action,buff.caster, tid);
				}
			}
			buff.owner.buff.removeBuff(action, b -> b.tid == buff.tid);
		}
	}

	@Override
	public void beforeSkillSettleAsTarget(SkillActionCtx action, SkillEffect effect) {
		if (action.getActor().getPid() != buff.caster.getPid()) {
			return;
		}
		effect.getTargetCtx(buff.owner.getPid()).addActorAttr(临时属性);
	}
}
